export const filterResult = (result: string) => {
  if (!result) return [];
  let s = result?.trim()?.split('\n');
  s = s.filter((item: string) => item.trim() !== '' && item.trim() !== '\n');
  return s || [];
};

export const isNotEmpty = (str: string) => {
  if (str === null || str === '' || typeof str === 'undefined') {
    return false;
  }

  return true;
};

export const getFileSize = (size: number) => {
  if (!size) return '';
  let num = 1024.0; //byte
  if (size < num) return size + 'B';
  if (size < Math.pow(num, 2)) return (size / num).toFixed(2) + 'KB'; //kb
  if (size < Math.pow(num, 3)) return (size / Math.pow(num, 2)).toFixed(2) + 'MB'; //M
  if (size < Math.pow(num, 4)) return (size / Math.pow(num, 3)).toFixed(2) + 'G'; //G
  return (size / Math.pow(num, 4)).toFixed(2) + 'T'; //T
};
//将\n替换成<p>包裹
export const replaceN = (str: any) => {
  return (
    str
      ?.split('\n')
      .map((p: any) => `<p>${p}</p>`)
      .join('') || ''
  );
};
